<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('BOM预增')"/>
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa fa-sitemap"></i> 物料分类
            </div>
            <div class="box-tools pull-right">
                <a type="button" class="btn btn-box-tool" href="javascript:void(0)" onclick="dept()" title="管理分类"><i class="fa fa-edit"></i></a>
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i class="fa fa-refresh"></i></button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>

<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12" >
                <label class="layui-form-label">品号</label>
                <input type="text" id="ino">&nbsp;

                <label class="layui-form-label">品名</label>
                <input type="text" id="inm">&nbsp;

                <label class="layui-form-label">规格</label>
                <input type="text" id="isp">&nbsp;
                <input value="搜索" type="button" onclick="$.table.search()">
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>

            <div class="col-sm-12" style="margin-top: 5px">
                <button type="button"  class="btn-default btn-xs" th:onclick="addRow()">新增</button>
                <button type="button"  class="btn-danger btn-xs">删除</button>
                <button type="button"  class="btn-primary btn-xs">确认返回</button>
            </div>

            <div class="col-sm-12 select-table2 table-striped2">
                <table id="bootstrap-table2"></table>
            </div>
        </div>
    </div>
</div>


<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js" />
<th:block th:include="include :: ztree-js" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:stta:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:stta:remove')}]];
    // var propertyStateDatas = [[${@dict.getType('sys_stta_state')}]];
    var prefix = ctx + "bom";

    // 在子页面中接收父页面传递的数据
    $(document).ready(function() {
        // 通过 window.opener 获取父页面传递的数据
        var data = window.opener.modalOptions.ItemNo;

        // 如果数据存在，可以使用它
        if (data) {
            console.log('接收到的数据:', data);
            // 你可以在这里处理数据，比如将数据渲染到模态框中
        // $('#someElement').text(JSON.stringify(data));  // 示例操作：将数据展示到某个元素
        }
    });


    $(function() {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({ initClosed: panehHidden, west__size: 185, resizeWithWindow: false });
        // 回到顶部绑定
        if ($.fn.toTop !== undefined) {
            var opt = {
                win:$('.ui-layout-center'),
                doc:$('.ui-layout-center')
            };
            $('#scroll-up').toTop(opt);
        }
        queryItemList();
        queryDeptTree();
        queryAddItem();
        queryTemporaryTable();
    });

    // 打开BOM选择框
    function selectRadioBom(){
        $.modal.open("选择BOM", prefix + "/openSelectBom", '1500', '900');
    }

    // 查询所有物料信息
    function queryItemList() {
        var options = {
            url: prefix + "/list",
            queryParams: queryParams,
           /* viewUrl: prefix + "/view/{id}",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            sortName: "createTime",
            sortOrder: "desc",
            modalName: "用户",*/
            columns: [{
                checkbox: true
            },
                {
                    field: 'itemNo',
                    title: '品号'
                },
                {
                    field: 'itemName',
                    title: '品名'
                },
                {
                    field: 'specification',
                    title: '规格'
                },
                {
                    field: 'f_000099',
                    title: '品牌',
                    visible: false
                },
                {
                    field: 'f_000073',
                    title: '项目号'
                },
                {
                    field: 'itemTypeName',
                    title: '品号群组',
                }]
        };
        $.table.init(options);
    }


    function queryTemporaryTable() {
        var data = [
            {
                id: "100",
                itemNo: "43B02052005",
                specification: "AAAAAAAAAAAbbb",
                f_000099: "怡合达",
                f_000073: "PT00522005",
                itemTypeName: "铁",
            },
        ]
        var options = {
            id: "bootstrap-table2",
            data: data,
            columns: [{
                checkbox: true
            },
                {
                    field: 'itemNo',
                    title: 'DetID'
                },
                {
                    field: 'FgItemNo',
                    title: '上一级品号'
                },
                {
                    field: 'specification',
                    title: '规格'
                },
                {
                    field: 'f_000099',
                    title: '品牌',
                    visible: false
                },
                {
                    field: 'f_000073',
                    title: '项目号'
                },
                {
                    field: 'itemTypeName',
                    title: '品号群组',
                }]
        };
        $.table.init(options);
    }

    //根据条件查询物料
    function queryParams(params) {
        var search = $.table.queryParams(params);
        search.itemNo = $("#ino").val();
        search.itemName = $("#inm").val();
        search.specification = $("#isp").val();
        // alert("1");
        return search;
    }

    //查询分类树
    function queryDeptTree()
    {
        var url = ctx + "bom/itemTreeData";
        var options = {
            url: url,
            expandLevel: 2,
            onClick : zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            $("#F1").val(treeNode.id);
            $("#parentId").val(treeNode.pId);
            $.table.search();
        }
    }

    function queryAddItem(){
        var options = {
            columns: [
                {
                    field: 'itemNo',
                    title: '品号'
                },
                {
                    field: 'itemName',
                    title: '品名'
                },
                {
                    field: 'specification',
                    title: '规格'
                },
                {
                    field: 'f_000099',
                    title: '品牌',
                    visible: false
                },
                {
                    field: 'f_000073',
                    title: '项目号'
                },
                {
                    field: 'itemTypeName',
                    title: '品号群组',
                }]
        };
        $.table.init(options);
    }

    // 展开
    $('#btnExpand').click(function() {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    //折叠
    $('#btnCollapse').click(function() {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    //刷新
    $('#btnRefresh').click(function() {
        queryDeptTree();
    });

    /* 自定义重置-表单重置/隐藏框/树节点选择色/搜索 */
    function resetPre() {
        resetDate();
        $("#user-form")[0].reset();
        $("#F1").val("");
        $("#parentId").val("");
        $(".curSelectedNode").removeClass("curSelectedNode");
        $.table.search();
    };

    function selectByButton(){
        // var ino = $("#ino").val();
        // $("#itemNo2").val(ino);
        // alert($("#itemNo2").val(ino));

        // $('#itemNo2').text(ino);
        //
        // $.table.search();
        //alert("1111111");
    }

    function addRow() {
        alert('1111111');
    }

</script>
</body>
<!-- 导入区域 -->
<!--<script id="importAsset" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <label>请下载这个模板进行导入</label>
                &nbsp; <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i
                    class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>-->
</html>